<?php

namespace App\Http\Controllers\Admin\User;

use App\Http\Controllers\Admin\BaseController;
use App\Repository\UserRepository;
use Illuminate\Http\Request;

use App\Http\Requests;
use BindService;

class ExceptionController extends BaseController
{

    protected $user;

    public function __construct(UserRepository $user)
    {
        $this->user = $user;
    }

    public function index()
    {
        $users = $this->user->getExceptionUsers();

        return view('admin.user.exception', ['users' => $users]);
    }

    public function getForm($number)
    {
        return BindService::getFormByNumber($number);
    }

    public function code($session, $nonce, $cookie=null)
    {
        $code = BindService::getCode($session, $cookie);

        return response($code)->header('Content-Type', 'image/gif');
    }

    public function bind(Request $request)
    {
        $result = BindService::bind($request);

        return $result === true ? $this->ok() : $this->fail($result);
    }
}
